package com.qf.smsplatform.strategy.mq;

import com.netflix.discovery.converters.Auto;
import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.strategy.service.StrategyExecutor;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听接口模块发送的消息
 */
@Component
public class PreSendQueueListener {

    @Autowired
    private StrategyExecutor strategyExecutor;

    @RabbitListener(queues = {RabbitMQConstants.TOPIC_PRE_SEND})
    public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
        // 获取消息
        System.out.println(submit);

        // 根据submit对象执行各个策略。。。
        strategyExecutor.execute(submit);

        // 对消息进行ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
